package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    ReservationService reservationService;

    @GetMapping("/reservation/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();

        int i= reservationService.getCancelledReservationCount(userId);
        return success(i);
    }

    @ApiOperation("新增预约")
    @PostMapping("/reservation")
    public ResponseResult save(@RequestBody ReservationDto dto){
        reservationService.save(dto);
        return success();
    }

//
//    @GetMapping("/memberElder/my")
//    public ResponseResult my(){
//        return success(1);
//    }

    @GetMapping("/reservation/countByTime")
    public ResponseResult countByTime(Long time){
        List<ReservationVo> reservationVo=reservationService.countByTime(time);
        return success(reservationVo);
    }

    @GetMapping("/reservation/page")
    public ResponseResult restPage(
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1")Integer pageNum,
            Integer status){
        PageResponse page = reservationService.pageList(pageSize,pageNum,status);
        return success(page);
    }


    @PutMapping("/reservation/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id){
        reservationService.cancel(id);
        return success();
    }
}